//
//  FlushUploadView.swift
//  GreenDeal
//
//  Created by Moennig Q on 14/2/2023.
//

import UIKit
import Lottie
class FlushUploadView: View {
    var stopFlushUploadClosure: (()->Void)?
    let uploadingLabel = ContentLabel(R.font.interMedium(size: 15))
    override func setUpView() {
        self.backgroundColor = UIColor(hexStr: "#00000080")
        let backView = CustomBackView()
        self.addSubview(backView)
        backView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.width.equalTo(240)
            make.height.greaterThanOrEqualTo(0)
        }
        //image view
        // someJSONFileName 指的就是用 AE 导出的动画 本地 JSON文件名
        let animationView = LottieAnimationView(name: "flushUpload")
        // 可以使用 frame 也可以 使用自动布局
        animationView.loopMode = .loop
        animationView.play()
        backView.addSubview(animationView)
        animationView.snp.makeConstraints { make in
            make.top.equalTo(50)
            make.height.width.greaterThanOrEqualTo(0)
            make.centerX.equalToSuperview()
        }
        //uploadingLabel
        uploadingLabel.text = "Uploading"
        backView.addSubview(uploadingLabel)
        uploadingLabel.snp.makeConstraints { make in
            make.top.equalTo(animationView.snp.bottom).offset(20)
            make.bottom.equalTo(-50)
            make.height.width.greaterThanOrEqualTo(0)
            make.centerX.equalToSuperview()
        }
        //close btn
        let closeBtn = UIButton()
        closeBtn.setImage(R.image.flush_upload_close(), for: UIControl.State.normal)
        backView.addSubview(closeBtn)
        closeBtn.snp.makeConstraints { make in
            make.top.equalTo(16)
            make.right.equalTo(-16)
            make.height.width.equalTo(24)
        }
        closeBtn.addTarget(self, action: #selector(closeBtnClick), for: UIControl.Event.touchUpInside)
    }
    @objc func closeBtnClick(){
        self.stopFlushUploadClosure?()
    }
}
